package com.example.baserecyclerviewadapterdemo.activity.node;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.entity.node.BaseNode;
import com.example.baserecyclerviewadapterdemo.R;
import com.example.baserecyclerviewadapterdemo.adapter.node.tree.NodeTreeAdapter;
import com.example.baserecyclerviewadapterdemo.base.BaseActivity;
import com.example.baserecyclerviewadapterdemo.entity.node.tree.FirstNode;
import com.example.baserecyclerviewadapterdemo.entity.node.tree.SecondNode;
import com.example.baserecyclerviewadapterdemo.entity.node.tree.ThirdNode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class NodeTreeActivity extends BaseActivity {
    private RecyclerView recyclerView;
    private NodeTreeAdapter adapter = new NodeTreeAdapter();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_node_tree);

        getParentToolbar().setTitle("NodeTree Use");
        getParentToolbar().setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        recyclerView = findViewById(R.id.rv_list);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);
        adapter.setList(getEntity());
        
        recyclerView.postDelayed(new Runnable() {
            @Override
            public void run() {
                SecondNode secondNode1 = new SecondNode(new ArrayList<>(),"SecondNode(This is added1)" );
                SecondNode secondNode2 = new SecondNode(new ArrayList<>(),"SecondNode(This is added2)" );
                List<BaseNode> secondNodes = new ArrayList<>();
                secondNodes.add(secondNode1);
                secondNodes.add(secondNode2);
                adapter.nodeAddData(adapter.getData().get(0),2,secondNodes);
                Toast.makeText(NodeTreeActivity.this, "新出入2个node", Toast.LENGTH_SHORT).show();
            }
        }, 2000);
    }

    private List<BaseNode> getEntity(){
        List<BaseNode> list = new ArrayList<>();
        for (int i = 0; i < 18; i++) {
            List<BaseNode> secondNodes = new ArrayList<>();
            for (int j = 0; j <= 5; j++) {
                List<BaseNode> thirdNodes = new ArrayList<>();
                for (int k = 0; k <= 3; k++) {
                    ThirdNode thirdNode = new ThirdNode("Third Node " + i + "_" + j + "_" + k);
                    thirdNodes.add(thirdNode);
                }
                SecondNode secondNode = new SecondNode(thirdNodes,"Second Node " + i + "_" + j);
                secondNodes.add(secondNode);
            }
            FirstNode firstNode = new FirstNode(secondNodes,"First Node " + i);
            firstNode.setExpanded(i == 0);
            list.add(firstNode);
        }
        return list;
    }
}
